﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARControlLib
{
	/// <summary>
	/// ControllBar.xaml 的交互逻辑
	/// </summary>
	public partial class ControllBar1 : UserControl
	{
		public ControllBar1()
		{
			this.InitializeComponent();
            SARCurrentSelectedIndex = 0;
		}

         private int currentSelectedIndex = 0;

        /// <summary>
        /// 获取当前选中的菜单项目，从0开始数
        /// </summary>
        public int SARCurrentSelectedIndex
        {
            get { return currentSelectedIndex; }
            set
            {
                currentSelectedIndex = value;
                selected1.Opacity = 0;
                selected2.Opacity = 0;
                selected3.Opacity = 0;
                selected4.Opacity = 0;

                txt1.FontWeight = FontWeights.Normal;
                txt1.Foreground = new SolidColorBrush(Color.FromRgb(0xa7,0xba,0xcc));
                txt2.FontWeight = FontWeights.Normal;
                txt2.Foreground = new SolidColorBrush(Color.FromRgb(0xa7, 0xba, 0xcc));
                txt3.FontWeight = FontWeights.Normal;
                txt3.Foreground = new SolidColorBrush(Color.FromRgb(0xa7, 0xba, 0xcc));
                txt4.FontWeight = FontWeights.Normal;
                txt4.Foreground = new SolidColorBrush(Color.FromRgb(0xa7, 0xba, 0xcc));
                    

                if (value == 0)
                {
                    selected1.Opacity = 1;
                    txt1.FontWeight = FontWeights.Bold;
                    txt1.Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0xff));
                }
                else if (value == 1)
                {
                    selected2.Opacity = 1;
                    txt2.FontWeight = FontWeights.Bold;
                    txt2.Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0xff));
                }
                else if (value == 2)
                {
                    selected3.Opacity = 1;
                    txt3.FontWeight = FontWeights.Bold;
                    txt3.Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0xff));
                }
                else if (value == 3)
                {
                    selected4.Opacity = 1;
                    txt4.FontWeight = FontWeights.Bold;
                    txt4.Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0xff));
                }
            }
        }

        /// <summary>
        /// 菜单被单击了的事件
        /// </summary>
        public event ControlBarClickHandler SARControlBarClick;

        private void mouse1_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 0)
            {
                return;
            }
            selected1.Opacity = 0.5;
        }

        private void mouse1_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 0)
            {
                return;
            }
            selected1.Opacity = 0;
        }

        private void mouse1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 0;
            if (SARControlBarClick != null)
            {
                SARControlBarClick.Invoke(0);
            }
        }

        private void mouse2_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 1)
            {
                return;
            }
            selected2.Opacity = 0.5;
        }

        private void mouse2_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 1)
            {
                return;
            }
            selected2.Opacity = 0;
        }

        private void mouse2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 1;
            if (SARControlBarClick != null)
            {
                SARControlBarClick.Invoke(1);
            }
        }

        private void mouse3_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 2)
            {
                return;
            }
            selected3.Opacity = 0.5;
        }

        private void mouse3_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 2)
            {
                return;
            }
            selected3.Opacity = 0;
        }

        private void mouse3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 2;
            if (SARControlBarClick != null)
            {
                SARControlBarClick.Invoke(2);
            }
        }

        private void mouse4_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 3)
            {
                return;
            }
            selected4.Opacity = 0.5;
        }

        private void mouse4_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 3)
            {
                return;
            }
            selected4.Opacity = 0;
        }

        private void mouse4_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARCurrentSelectedIndex = 3;
            if (SARControlBarClick != null)
            {
                SARControlBarClick.Invoke(3);
            }
        }
	}
}